<style>
  .error {color : red}
</style>
<div class="container-fluid p-t-10">
  <ol class="breadcrumb" style="font-weight: 700;margin-bottom: 10px">
    <li class="active">修改密码</li>
  </ol>
  <div class="row">
    <div class="col-lg-12">
      <div class="card">

        <div class="card-body">
          <h1>修改密码</h1>
          <form id="add-form" action="/index/updatepwd" method="post" class="row">
            <div class="form-group col-md-12 hide">
              <label for="id">编号</label>
              <input type="text" class="form-control" id="id" name="id" readonly value="{$data? $data.id:''}"/>
            </div>

            <div class="form-group col-md-12">
              <label for="username">用户名</label>
              <input type="text" class="form-control" id="username" name="username" value="{$data.username}" readonly />
            </div>

              <div class="form-group col-md-12">
                  <label for="password">原密码</label>
                  <input type="password" class="form-control" id="password" name="password" value="" />
              </div>

              <div class="form-group col-md-12">
                  <label for="pwdnew">新密码</label>
                  <input type="password" class="form-control" id="pwdnew" name="pwdnew" value="" />
              </div>

              <div class="form-group col-md-12">
                  <label for="new_repeat">重复新密码</label>
                  <input type="password" class="form-control" id="new_repeat" name="new_repeat" value="" />
              </div>

            <div class="form-group col-md-12">
              <button type="submit" class="btn btn-primary " target-form="add-form">确 定</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<script>

  $(function(){
    $("#add-form").validate({

        rules: {
            'password': {
                required: true,
                password: true,
                remote:{
                    url: '/index/updatepwd',
                    type: "post",               //数据发送方式
                    dataType: "json",           //接受数据格式
                    data: {                     //要传递的数据
                        pwd: function() {
                            return $('#password').val();
                        },
                        type:'checkpwd'
                    }
                }
            },
            'pwdnew' : {
                required: true,
                password : true
            },
            'new_repeat' : {
                required: true,
                password : true
            }
        },
        messages:{
            password :{
                remote : '原密码不匹配！'
            }
        },

        submitHandler:function(){
            var password = $('#password').val();
            var pwdnew = $('#pwdnew').val();
            var new_repeat = $('#new_repeat').val();
            if(pwdnew && new_repeat && pwdnew!==new_repeat){
                lightyear.notify('两次输入密码不同!请核对~', 'danger');
                return false;
            }

            $._ajax({
                url:'/index/updatepwd.html',
                type:'post',
                data:{
                    password:password,
                    pwdnew:pwdnew,
                    new_repeat:new_repeat,
                    type: 'updatepwd'
                }
            }).done(function(data){
                if(data){
                    lightyear.notify('修改成功~', 'success');
                }else{
                    lightyear.notify('修改失败~', 'danger');
                    setTimeout(function() {
                        window.location.reload();
                    }, 1e3);
                }
            });
            return false;
        }
    });
  });
</script>


